package com.wangdao.wechatmall.util;

import com.wangdao.wechatmall.bean.vo.admin.PermissionSecondChildrenVO;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: ApiTransformUtils
 * @Description api转换工具类
 * @Author Xinhao Yi
 * @Date 2021/7/12  21:35
 */
public class ApiTransformUtils {

    public static String apiTransform(String permissionString) {

        //咱们要根据这些api拼出一个嵌套的map来，再逐层遍历这个map来得到我们的返回结果
        //嵌套map
        Map<String, Map<String, List<PermissionSecondChildrenVO>>> outsideMap = new HashMap<>();



        //开始循环
        //咱们循环两次，第一次循环，把内层map有哪些都创建好，比如其中一个内层map{"管理员管理","角色管理","对象存储","操作日志"}，第二次循环再去填充对应的内层map

        //permissionString是api的字符串
        //用冒号把api分开
        String[] splitPermissions = permissionString.split(":");

        //拿到第二个字符，来检查它是什么
        String secondPermissionWord = splitPermissions[1];
        //拿到第三个字符，后面会用到
        String thirdPermissionWord = splitPermissions[2];

        //记录一下lableFirstLevel和lableSecondLevel
        String lableFirstLevel = "";
        String lableSecondLevel = "";

        switch (secondPermissionWord) {
                /*
                系统管理
                 */
            case "admin":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "系统管理";
                lableSecondLevel = "管理员管理";
                if (!outsideMap.containsKey("系统管理")) {
                    outsideMap.put("系统管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("系统管理");
                if (!insideMap.containsKey("管理员管理")) {
                    insideMap.put("管理员管理", new ArrayList<>());
                }
                break;
            }
            case "role":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "系统管理";
                lableSecondLevel = "角色管理";
                if (!outsideMap.containsKey("系统管理")) {
                    outsideMap.put("系统管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("系统管理");
                if (!insideMap.containsKey("角色管理")) {
                    insideMap.put("角色管理", new ArrayList<>());
                }
                break;
            }
            case "storage":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "系统管理";
                lableSecondLevel = "对象存储";
                if (!outsideMap.containsKey("系统管理")) {
                    outsideMap.put("系统管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("系统管理");
                if (!insideMap.containsKey("对象存储")) {
                    insideMap.put("对象存储", new ArrayList<>());
                }
                break;
            }
            case "log":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "系统管理";
                lableSecondLevel = "操作日志";
                if (!outsideMap.containsKey("系统管理")) {
                    outsideMap.put("系统管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("系统管理");
                if (!insideMap.containsKey("操作日志")) {
                    insideMap.put("操作日志", new ArrayList<>());
                }
                break;
            }
                /*
                商场管理
                 */
            case "brand":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "商场管理";
                lableSecondLevel = "品牌管理";
                if (!outsideMap.containsKey("商场管理")) {
                    outsideMap.put("商场管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("商场管理");
                if (!insideMap.containsKey("品牌管理")) {
                    insideMap.put("品牌管理", new ArrayList<>());
                }
                break;
            }
            case "issue":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "商场管理";
                lableSecondLevel = "通用问题";
                if (!outsideMap.containsKey("商场管理")) {
                    outsideMap.put("商场管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("商场管理");
                if (!insideMap.containsKey("通用问题")) {
                    insideMap.put("通用问题", new ArrayList<>());
                }
                break;
            }
            case "order":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "商场管理";
                lableSecondLevel = "订单管理";
                if (!outsideMap.containsKey("商场管理")) {
                    outsideMap.put("商场管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("商场管理");
                if (!insideMap.containsKey("订单管理")) {
                    insideMap.put("订单管理", new ArrayList<>());
                }
                break;
            }
            case "category":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "商场管理";
                lableSecondLevel = "类目管理";
                if (!outsideMap.containsKey("商场管理")) {
                    outsideMap.put("商场管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("商场管理");
                if (!insideMap.containsKey("类目管理")) {
                    insideMap.put("类目管理", new ArrayList<>());
                }
                break;
            }
            case "keyword":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "商场管理";
                lableSecondLevel = "关键词";
                if (!outsideMap.containsKey("商场管理")) {
                    outsideMap.put("商场管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("商场管理");
                if (!insideMap.containsKey("关键词")) {
                    insideMap.put("关键词", new ArrayList<>());
                }
                break;
            }
                /*
                用户管理
                 */
            case "collect":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "用户管理";
                lableSecondLevel = "用户收藏";
                if (!outsideMap.containsKey("用户管理")) {
                    outsideMap.put("用户管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("用户管理");
                if (!insideMap.containsKey("用户收藏")) {
                    insideMap.put("用户收藏", new ArrayList<>());
                }
                break;
            }
            case "footprint":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "用户管理";
                lableSecondLevel = "用户足迹";
                if (!outsideMap.containsKey("用户管理")) {
                    outsideMap.put("用户管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("用户管理");
                if (!insideMap.containsKey("用户足迹")) {
                    insideMap.put("用户足迹", new ArrayList<>());
                }
                break;
            }
            case "feedback":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "用户管理";
                lableSecondLevel = "意见反馈";
                if (!outsideMap.containsKey("用户管理")) {
                    outsideMap.put("用户管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("用户管理");
                if (!insideMap.containsKey("意见反馈")) {
                    insideMap.put("意见反馈", new ArrayList<>());
                }
                break;
            }
            case "history":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "用户管理";
                lableSecondLevel = "搜索历史";
                if (!outsideMap.containsKey("用户管理")) {
                    outsideMap.put("用户管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("用户管理");
                if (!insideMap.containsKey("搜索历史")) {
                    insideMap.put("搜索历史", new ArrayList<>());
                }
                break;
            }
            case "user":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "用户管理";
                lableSecondLevel = "会员管理";
                if (!outsideMap.containsKey("用户管理")) {
                    outsideMap.put("用户管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("用户管理");
                if (!insideMap.containsKey("会员管理")) {
                    insideMap.put("会员管理", new ArrayList<>());
                }
                break;
            }
            case "address":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "用户管理";
                lableSecondLevel = "收货地址";
                if (!outsideMap.containsKey("用户管理")) {
                    outsideMap.put("用户管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("用户管理");
                if (!insideMap.containsKey("收货地址")) {
                    insideMap.put("收货地址", new ArrayList<>());
                }
                break;
            }
                /*
                配置管理
                 */
            case "config":
                //配置管理config比较特殊，要查找config后面一个字段nextKeyWord才能确定具体是哪个功能
            {
                lableFirstLevel = "配置管理";

                //先把内部map创建好
                if (!outsideMap.containsKey("配置管理")) {
                    outsideMap.put("配置管理", new HashMap<>());
                }
                //查找config后面一个字段nextKeyWord
                //再来确定内部map里面的各个key
                String nextKeyWord = splitPermissions[2];
                if ("wx".equals(nextKeyWord)) {
                    lableSecondLevel = "小程序配置";
                    //拿到内部map，并把list放进去
                    Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("配置管理");
                    if (!insideMap.containsKey("小程序配置")) {
                        insideMap.put("小程序配置", new ArrayList<>());
                    }
                } else if ("express".equals(nextKeyWord)) {
                    lableSecondLevel = "运费配置";
                    //拿到内部map，并把list放进去
                    Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("配置管理");
                    if (!insideMap.containsKey("运费配置")) {
                        insideMap.put("运费配置", new ArrayList<>());
                    }
                } else if ("mall".equals(nextKeyWord)) {
                    lableSecondLevel = "商场配置";
                    //拿到内部map，并把list放进去
                    Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("配置管理");
                    if (!insideMap.containsKey("商场配置")) {
                        insideMap.put("商场配置", new ArrayList<>());
                    }
                } else if ("order".equals(nextKeyWord)) {
                    lableSecondLevel = "订单配置";
                    //拿到内部map，并把list放进去
                    Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("配置管理");
                    if (!insideMap.containsKey("订单配置")) {
                        insideMap.put("订单配置", new ArrayList<>());
                    }
                }
                break;
            }

                /*
                推广管理
                 */
            case "ad":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "推广管理";
                lableSecondLevel = "广告管理";
                if (!outsideMap.containsKey("推广管理")) {
                    outsideMap.put("推广管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("推广管理");
                if (!insideMap.containsKey("广告管理")) {
                    insideMap.put("广告管理", new ArrayList<>());
                }
                break;
            }
            case "topic":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "推广管理";
                lableSecondLevel = "专题管理";
                if (!outsideMap.containsKey("推广管理")) {
                    outsideMap.put("推广管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("推广管理");
                if (!insideMap.containsKey("专题管理")) {
                    insideMap.put("专题管理", new ArrayList<>());
                }
                break;
            }
            case "coupon":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "推广管理";
                lableSecondLevel = "优惠劵管理";
                if (!outsideMap.containsKey("推广管理")) {
                    outsideMap.put("推广管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("推广管理");
                if (!insideMap.containsKey("优惠劵管理")) {
                    insideMap.put("优惠劵管理", new ArrayList<>());
                }
                break;
            }
            case "groupon":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "推广管理";
                lableSecondLevel = "团购管理";
                if (!outsideMap.containsKey("推广管理")) {
                    outsideMap.put("推广管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("推广管理");
                if (!insideMap.containsKey("团购管理")) {
                    insideMap.put("团购管理", new ArrayList<>());
                }
                break;
            }
                /*
                商品管理
                 */
            case "goods":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "商品管理";
                lableSecondLevel = "商品管理";
                if (!outsideMap.containsKey("商品管理")) {
                    outsideMap.put("商品管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("商品管理");
                if (!insideMap.containsKey("商品管理")) {
                    insideMap.put("商品管理", new ArrayList<>());
                }
                break;
            }
            case "comment":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "商品管理";
                lableSecondLevel = "评论管理";
                if (!outsideMap.containsKey("商品管理")) {
                    outsideMap.put("商品管理", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("商品管理");
                if (!insideMap.containsKey("评论管理")) {
                    insideMap.put("评论管理", new ArrayList<>());
                }
                break;
            }

                /*
                其他
                 */
            case "index":
                //把内部map放进外部map中
                //如果对应的内部map不存在，就创建一个内部map放进去
            {
                lableFirstLevel = "其他";
                lableSecondLevel = "权限测试";
                if (!outsideMap.containsKey("其他")) {
                    outsideMap.put("其他", new HashMap<>());
                }
                //拿到内部map，并把list放进去
                Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("其他");
                if (!insideMap.containsKey("权限测试")) {
                    insideMap.put("权限测试", new ArrayList<>());
                }
                break;
            }
                /*
                统计管理
                 */
            case "stat":
                //统计管理stat比较特殊，要坚持后面一个字段才能确定功能
            {
                lableFirstLevel = "统计管理";

                if (!outsideMap.containsKey("统计管理")) {
                    outsideMap.put("统计管理", new HashMap<>());
                }
                //查找config后面一个字段nextKeyWord
                //再来确定内部map里面的各个key
                String nextKeyWord = splitPermissions[2];
                if ("user".equals(nextKeyWord)) {
                    lableSecondLevel = "用户统计";
                    //拿到内部map，并把list放进去
                    Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("统计管理");
                    if (!insideMap.containsKey("用户统计")) {
                        insideMap.put("用户统计", new ArrayList<>());
                    }
                } else if ("order".equals(nextKeyWord)) {
                    lableSecondLevel = "订单统计";
                    //拿到内部map，并把list放进去
                    Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("统计管理");
                    if (!insideMap.containsKey("订单统计")) {
                        insideMap.put("订单统计", new ArrayList<>());
                    }
                } else if ("goods".equals(nextKeyWord)) {
                    lableSecondLevel = "商品统计";
                    //拿到内部map，并把list放进去
                    Map<String, List<PermissionSecondChildrenVO>> insideMap = outsideMap.get("统计管理");
                    if (!insideMap.containsKey("商品统计")) {
                        insideMap.put("商品统计", new ArrayList<>());
                    }
                }
                break;
            }
        }

        //这之后我们就要用api填充内部表insideMap
        //首先根据lableFirstLevel和lableSecondLevel拿到最底层的List<PermissionSecondChildrenVO>
        List<PermissionSecondChildrenVO> childList = outsideMap.get(lableFirstLevel).get(lableSecondLevel);
        //再拿到我们要封装的对象
        PermissionSecondChildrenVO childrenBean = new PermissionSecondChildrenVO();

        //然后我们应该先去处理比较特殊的api
        //系统管理----->角色管理
        if ("角色管理".equals(lableSecondLevel)) {
            //权限变更和权限详情的区分
            //权限变更
            if ("admin:role:permission:update".equals(permissionString)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("权限变更");
            }
            //权限详情
            else if ("admin:role:permission:get".equals(permissionString)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("权限详情");
            }
            //角色编辑
            else if ("update".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("角色编辑");
            }
            //角色查询
            else if ("list".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("角色查询");
            }
            //角色详情
            else if ("read".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("角色详情");
            }
            //角色删除
            else if ("delete".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("角色删除");
            }
            //角色添加
            else if ("create".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("角色添加");
            }
        }

        //商场管理----->订单管理
        else if ("订单管理".equals(lableSecondLevel)) {
            //详情
            if ("detail".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("详情");
            }
            //订单发货
            else if ("ship".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("订单发货");
            }
            //订单退货
            else if ("refund".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("订单退款");
            }
            //订单商品回复
            else if ("reply".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("订单商品回复");
            }
            //查询
            else if ("list".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("查询");
            }

        }

        //配置管理 ------> 底下的都要特殊处理
        //lableFirstLevel一级标签
        else if ("配置管理".equals(lableFirstLevel)) {
            if ("updateConfigs".equals(splitPermissions[3])) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("编辑");
            } else if ("list".equals(splitPermissions[3])) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("详情");
            }
        }

        //推广管理----->优惠劵管理
        else if ("优惠劵管理".equals(lableSecondLevel)) {
            if ("listuser".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("查询用户");
            }
            if ("update".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("编辑");
            } else if ("list".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("查询");
            } else if ("read".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("详情");
            } else if ("delete".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("删除");
            } else if ("create".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("添加");
            }
        }

        //推广管理----->团购管理
        else if ("团购管理".equals(lableSecondLevel)) {
            if ("listRecord".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("详情");
            }
            if ("update".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("编辑");
            } else if ("list".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("查询");
            } else if ("delete".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("删除");
            } else if ("create".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("添加");
            }
        }

        //商品管理------>商品管理
        else if ("商品管理".equals(lableSecondLevel)) {
            //详情
            if ("detail".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("详情");
            }
            //编辑
            if ("update".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("编辑");
            }
            //查询
            if ("list".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("查询");
            }
            //删除
            if ("delete".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("删除");
            }
            //上架
            else if ("create".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("上架");
            }
        }

        //其他---->权限测试
        else if ("权限测试".equals(lableSecondLevel)) {
            //权限写
            if ("write".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("权限写");
            }
            //权限读
            else if ("read".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("权限读");
            }
        }

        //统计管理 ------>底下的都要特殊处理
        //lableFirstLevel一级标签
        else if ("统计管理".equals(lableFirstLevel)) {
            if ("user".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("查询");
            } else if ("order".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("查询");
            } else if ("goods".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("查询");
            }
        }
        //剩下的都是普通的增删改查api，统一处理即可
        //编辑、查询、详情、删除、添加
        else {
            if ("update".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("编辑");
            } else if ("list".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("查询");
            } else if ("read".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getGETApi(permissionString));
                childrenBean.setLabel("详情");
            } else if ("delete".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("删除");
            } else if ("create".equals(thirdPermissionWord)) {
                childrenBean.setId(permissionString);
                childrenBean.setApi(getPOSTApi(permissionString));
                childrenBean.setLabel("添加");
            }
        }

        return childrenBean.getApi();
    }


    /**
     * 工具类，生成GET api
     *
     * @param permissionString
     * @return
     */
    //输入
    //"admin:admin:create"
    //"admin:role:permission:update"
    //结果：GET /admin/role/permissions
    private static String getGETApi(String permissionString) {
        //用冒号把permissionString分隔开
        String[] splitPermissions = permissionString.split(":");
        String api = "GET /" + splitPermissions[0] + "/" + splitPermissions[1] + "/" + splitPermissions[2];
        return api;
    }

    /**
     * 工具类，生成POST api
     *
     * @param permissionString
     * @return
     */
    private static String getPOSTApi(String permissionString) {
        //用冒号把permissionString分隔开
        String[] splitPermissions = permissionString.split(":");
        //只要前三个字段，如果有第四个字段，会抛弃掉
        String api = "POST /" + splitPermissions[0] + "/" + splitPermissions[1] + "/" + splitPermissions[2];
        return api;
    }


}
